package validate

import (
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
	"reflect"
)

var validate = binding.Validator.Engine().(*validator.Validate)

func Var(field interface{}, tag string) error {
	return validate.Var(field, tag)
}

func RegisterValidation(tag string, fn validator.Func) error {
	return validate.RegisterValidation(tag, fn)
}

func IsDefaultField(fl validator.FieldLevel) bool {
	field, kind, ok := fl.GetStructFieldOK()
	if !ok {
		return false
	}

	switch kind {
	case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
		return field.IsNil()
	default:
		return field.IsValid() && field.IsZero()
	}
}
